package com.hnkywl.sts.action.organ;

import com.hnkywl.sts.entity.organ.Wls;
import com.hnkywl.sts.entity.organ.Ysgj;
import com.hnkywl.sts.service.organ.WlsService;
import com.hnkywl.sts.util.EasyuiAdapter;
import net.ruixin.web.struts2.SimpleActionSupport;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: Administrator
 * Date: 13-3-29
 * Time: 上午10:42
 * To change this template use File | Settings | File Templates.
 */
@Namespace("/organ/wls")
public class WlsAction extends SimpleActionSupport {
    private WlsService wlsService;
    //传入的wls实体
    private Wls wls;
    //传入的物流商的ID
    private Long wlsId;
    //传入的运输工具的集合
    private List<Ysgj> ysgj;

    /**
     * 方法名:     addWls
     * 功能描述:      获取物流商列表
     * 输入参数:    <@param Wls wls实例>
     * 异常:      <RuntimeException  Exception>
     * 创建人:     hfj
     * 创建日期:   13-2-19上午10:47
     * 修改人:     hfj
     * 修改日期:   13-2-19上午10:47
     */
    @Action("add_wls")
    public void addWls() {
        try {
            wlsService.saveWls(wls);
            renderText("{\"statusCode\":\"200\", \"message\":\"添加成功\", \"operationType\":\"add\"}");
        } catch (Exception e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }

    /**
     * 方法名:     deleteWls
     * 功能描述:      删除物流商
     * 输入参数:    <@param Long  wlsId>
     * 异常:      <RuntimeException  Exception>
     * 创建人:     hfj
     * 创建日期:   13-2-19上午10:47
     * 修改人:     hfj
     * 修改日期:   13-2-19上午10:47
     */
    @Action("delete_wls")
    public void deleteWls() {
        try {
            Wls wls1 = wlsService.findWlsDetail(wlsId);
            wlsService.deleteWls(wls1);
            renderJson("{\"statusCode\":\"200\", \"message\":\"删除物流商成功\", \"operationType\":\"delete\"}");
        } catch (Exception e) {
            e.printStackTrace();
            renderJson("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }

    }

    /**
     * 方法名:     updateWls
     * 功能描述:      修改物流商
     * 输入参数:    <@param Wls  wls>
     * 异常:      <RuntimeException  Exception>
     * 创建人:     hfj
     * 创建日期:   13-2-19上午10:47
     * 修改人:     hfj
     * 修改日期:   13-2-19上午10:47
     */
    @Action("update_wls")
    public void updateWls() {
        try {
            wlsService.updateWls(wls);
            renderText("{\"statusCode\":\"200\", \"message\":\"修改物流商成功\", \"operationType\":\"delete\"}");
        } catch (Exception e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }

    }

    @Action("wlsInuseList")
    public void wls_inuse_list() {
        String[] propertyNames = {"id", "qc"};
        this.renderJson(EasyuiAdapter.getJsonForCombo(this.wlsService.findeAllInuse(),propertyNames));
    }
    @Action("allwlsList")
    public void allwlsList() {
        String[] propertyNames = {"id", "qc"};
        this.renderJson(EasyuiAdapter.getJsonForCombo(this.wlsService.findAllWls(),propertyNames));
    }
    public List<Ysgj> getYsgj() {
        return ysgj;
    }

    public void setYsgj(List<Ysgj> ysgj) {
        this.ysgj = ysgj;
    }

    public Wls getWls() {
        return wls;
    }

    public void setWls(Wls wls) {
        this.wls = wls;
    }


    public Long getWlsId() {
        return wlsId;
    }

    public void setWlsId(Long wlsId) {
        this.wlsId = wlsId;
    }


    @Autowired
    public void setWlsService(WlsService wlsService) {
        this.wlsService = wlsService;
    }

}
